
*------------------------------------------------------------------------------*
* LEGISLATIVE PROCEDURES
*
* Additional specs: GOV_POS if ideological data is missing
*
* Version:	2016-10-28
* Changes:	2016-??-??: First release
*------------------------------------------------------------------------------*



* ----------------------
* Merge positions

use tmp_eu_council, clear
keep g103 g104 g105 EUCOU_POS european_council

merge m:m g105 using tmp_commission, 	keepusing(COMM_POS european_commission) nogen
merge m:m g105 using tmp_councilofmin, 	keepusing(COUNCIL_POS councilofministers) nogen
merge m:m g105 using tmp_euparliament,	keepusing(EP_POS european_parliament) nogen

by g105, sort: keep if _n == 1
save tmp_eu_legisprocess, replace



* ----------------------
* Adjust positions if European Council is principal

if "$principal" == "principal" {

	gen principal = "principal"
	clonevar orig_COMM_POS  	= COMM_POS
	clonevar orig_COUNCIL_POS  	= COUNCIL_POS
	
	replace COMM_POS 	= (COMM_POS 	+ EUCOU_POS) /2
	replace COUNCIL_POS = (COUNCIL_POS 	+ EUCOU_POS) /2
}
else if "$principal" == "no" {
		gen principal = "no"
}
lab var principal "Your model choice of the Principal-Agent Relationship"



* ----------------------
* Interinstitutional bargaining

gen _____LEGISLATIVE_PROCEDURES = .


// Consultation
gen leg_consultation = COUNCIL_POS
lab var leg_consultation "Legislative Process: Position under consultion procedure"


// Cooperation
local commonpos "$commonpos"	// "translate" global to local, which can be tokenized
*di "`commonpos'"
gen commonpos = "`commonpos'"
lab var commonpos "Power scores for common position"
tokenize `commonpos', parse(":")	// tokenize power scores for council and commission
gen pscouncil = `1'
gen pscommission = `3'
gen pstotal = pscouncil + pscommission


	* Common position of Council and Commission
gen common_position = ( COUNCIL_POS*pscouncil + COMM_POS*pscommission) / pstotal

	* 2nd reading by EP
gen second_reading = ( common_position + EP_POS) /2

	* Common position 2: if 2nd reading closer to commission -> 2nd reading (=1), else -> stick to common pos. (=0)
gen		check = 1	if abs(second_reading - COMM_POS) < abs(common_position - COMM_POS)
replace check = 0	if abs(second_reading - COMM_POS) > abs(common_position - COMM_POS)
gen 	common_position2 = second_reading  if check == 1
replace common_position2 = common_position if check == 0

lab var common_position "Cooperation: Common position of Council and Commission"
lab var second_reading "Cooperation: 2nd reading by EP"

	* Amendment by Council
gen leg_cooperation = ( common_position2 + COUNCIL_POS ) /2
lab var leg_cooperation "Legislative Process: Position under cooperation procedure"


// Co-Decision I
clonevar leg_codecision1 = common_position
lab var leg_codecision1 "Legislative Process: Position under co-decision I procedure"


// Co-Decision II
local codec2 "$codec2"	// "translate" global to local, which can be tokenized
di "`codec2'"
gen codec2 = "`codec2'"
lab var codec2 "Power scores for co-decision II"
tokenize `codec2', parse(":")	// tokenize power scores for council and commission
gen pscodec_council = `1'
gen pscodec_ep = `3'
gen pscodec_total = pscodec_council + pscodec_ep

gen leg_codecision2 = ( COUNCIL_POS*pscodec_council + EP_POS*pscodec_ep) / pscodec_total
lab var leg_codecision2 "Legislative Process: Position under co-decision II procedure"



* ----------------------
* THE position of the EU

gen  EU_POS = .
lab var EU_POS "EU: Position of the European Union"

replace EU_POS = leg_consultation				if g105<=tq(1987q2)						// "Luxembourg compromise", consultation ( -1987q2)
replace EU_POS = leg_cooperation				if g105 >=tq(1987q3) & g105<=tq(1993q3)	// Single European Act, cooperation (1987q3-1993q3)
replace EU_POS = leg_codecision1				if g105 >=tq(1993q4) & g105<=tq(1999q1)	// Maastricht Treaty, co-decision I (1993q4 - 1999q1)
replace EU_POS = leg_codecision2				if g105 >=tq(1999q2) & g105<=tq(2009q4)	// Amsterdam Treaty, co-decision II (1999q2-2009q4)
replace EU_POS = leg_codecision2				if g105 >=tq(2010q1)					// Lisbon Treaty, co-decision II with rotating presidency (2010q1- ) [if specified]



* ----------------------
* Save temporary file

drop ps* check
clonevar techq = g105	// "merge" ids ~ membership & quarter
gen eu = 1	 
save, replace
